package observer.desc;

import java.util.HashSet;
import java.util.Set;

public class GuPiao implements Subject {
    private double price;
    Set<Observer> observers=new HashSet<>();
    public void setPrice(double price){
        this.price=price;
        notifyObservers();

    }

    @Override
    public void attach(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void delete(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        for (Observer ob:observers){
            ob.update(price);
        }
    }
}
